package com.hhl.jvm.hotspot.src.share.vm.oops;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Bei·S·J on 2021/6/24 下午6:09
 * ClassFile --字节码的文件
 */
@Data
public class InstanceKlass extends Klass {
    /**
     * magic 魔数
     * minorVersion 次版本号
     * majorVersion 主版本号
     * constantPool 常量池
     * accessFlag 访问控制权限标识
     * thisClass 当前类名
     * superClass 父类名
     * interfacesLength 实现的接口个数 //todo 它实现的？
     * interfaceInfos 实现的接口信息的集合
     * fieldsLength 属性长度
     * fields  属性集合
     * methodLength 成员方法数量
     * methods 成员方法数组
     * attributeLength 类属性
     * attributeInfos 类属性数组
     */
    private byte[] magic = new byte[4];
    private byte[] minorVersion = new byte[2];
    private byte[] majorVersion = new byte[2];
    private ConstantPool constantPool;
    private int accessFlag;
    private int thisClass;
    private int superClass;
    private int interfacesLength;
    private List<InterfaceInfo> interfaceInfos = new ArrayList<>();
    private int fieldsLength;
    private List<FieldInfo> fields = new ArrayList<>();
    private int methodLength;
    private MethodInfo[] methods;
    private int attributeLength;
    private List<AttributeInfo> attributeInfos = new ArrayList<>();

    public InstanceKlass() {
        constantPool = new ConstantPool();
        constantPool.setKlass(this);
    }

    public void initMethodsContainer() {
        methods = new MethodInfo[methodLength];
    }

    @Override
    public String toString() {
        return "InstanceKlass{ }";
    }
}
